﻿using Common.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Wallpaper.Models.DTOs.Requests.Menu;
using Wallpaper.Models.DTOs.Responses;
using Wallpaper.Models.Options;
using Wallpaper.Services.IService;
using WallpaperApi.Filter;

namespace WallpaperApi.Controllers
{
    [Route("api/menus")]
    [ApiController]
    public class MenuController : BaseController
    {
        private readonly IMenuService _menuService;

        public MenuController(IMenuService menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="request">菜单请求参数</param>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(ModelValidationFilter))]
        public async Task<ApiResponse<bool>> CreateMenu([FromBody] MenuRequest request)
        {
            await _menuService.CreateAsync(request);
            return ApiResponse<bool>.Success();
        }

        /// <summary>
        /// 更新菜单
        /// </summary>
        /// <param name="id">菜单ID</param>
        /// <param name="request">菜单请求参数</param>
        /// <returns></returns>
        [HttpPut("{id}")]
        [ServiceFilter(typeof(ModelValidationFilter))]
        public async Task<ApiResponse<bool>> UpdateMenu(string id, [FromBody] MenuRequest request)
        {
            await _menuService.UpdateAsync(id, request);
            return ApiResponse<bool>.Success();
        }


        /// <summary>
        /// 获取侧边栏菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("sidebar")]
        public async Task<ApiResponse<List<MenuSidebarResponse>>> GetMenuSidebar()
        {
            List<MenuSidebarResponse> result = await _menuService.GetMenuSidebarInfoAsync(AdminId);
            return ApiResponse<List<MenuSidebarResponse>>.Success(result);
        }


      
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResponse<List<MenuSidebarResponse>>> GetMenuSidebarInfo()
        {
            List<MenuSidebarResponse> list = await _menuService.GetMenuSidebarInfoAsync();
            return ApiResponse<List<MenuSidebarResponse>>.Success(list);
        }

     


        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("all-menus")]
        public async Task<ApiResponse<List<MenuOptions>>> GetAllMenus()
        {
            List<MenuOptions> options= await _menuService.GetAllMenusAsync();
            return ApiResponse<List<MenuOptions>>.Success(options);
        }
    }
}
